package api

import (
	"dev.ixmxm.top/rms/managers/usermanager"
	"dev.ixmxm.top/rms/model"
	"dev.ixmxm.top/rms/utils/base64"
	"dev.ixmxm.top/rms/utils/page"
)

type emptyParams struct {
}

type addRobotTypeParams struct {
	model.RobotType
}

// addRobotGroupParams 添加机器人分组参数
type addRobotGroupParams struct {
	model.RobotGroup
}

// updateRobotGroupParams 添加机器人分组参数
type updateRobotGroupParams struct {
	ID      string   `json:"id" binding:"required"`
	Name    string   `json:"name"`
	MapList []string `json:"map_list"`
}

// getRobotGroupParams 获取机器人分组
type getRobotGroupParams struct {
	ID string `form:"id" binding:"required"`
}

// getGroupRobotsParams 获取机器人分组
type getGroupRobotsParams struct {
	ID string `form:"id"`
}

type getProjectParams struct {
	ProjectId string `form:"project_id"`
	AgvId     string `form:"agv_id"`
}
type setElevatorParams struct {
	model.Elevator
}

type setElevatorLevelParams struct {
	DeviceCode string             `json:"device_code" binding:"required"` //设备编号
	Info       model.ElevatorInfo `json:"info" binding:"required"`        //设备信息
}
type setMapRelationParams struct {
	model.MapRelation
}
type saveRobotTypeParams struct {
	CID int `form:"category_id" binding:"required"`
	model.RobotType
}
type saveResourcePictureParams struct {
	model.ResourcePicture
}

type addRobotParams struct {
	model.RobotAccount
}

type saveRobotParams struct {
	model.RobotAccount
}

type robotOperateCMD uint8

const (
	ROCMDEnable  robotOperateCMD = 1 //启用
	ROCMDDisable robotOperateCMD = 2 //禁用
	ROCMDDelete  robotOperateCMD = 3 //删除
)

type robotOperateParams struct {
	AgvID      string          `json:"agv_id" binding:"required"`                  //机器人ID
	OperateCMD robotOperateCMD `json:"operate_cmd" binding:"required,oneof=1 2 3"` //操作命令：1=启用、2=禁用、3=删除
}

type robotSoftStopParams struct {
	IsStop bool `json:"is_stop"` //是否急停：true=急停、false=取消急停
}
type robotBroadcastErrParams struct {
	ErrAgvId string `json:"err_agv_id" binding:"required"` //报错小车编号
	ErrCode  int    `json:"err_code" binding:"required"`   //报错码（模式：0：无语音播报，1：语音播报）
	ErrLevel string `json:"err_level" binding:"required"`  //设备信息（warn:调用一次报警一次，error:持续报警，需人工复位）
	ErrMsg   string `json:"err_msg" `
}

type operateRobotTypeCMD uint8

const (
	RTOCMDDelete operateRobotTypeCMD = 1
)

type RobotTypeDeleteParams struct {
	CategoryID int `form:"category_id" binding:"required"`
}

type addTaskParams struct {
	model.Task
}

type getTaskParams struct {
	TaskID uint64 `form:"task_id"`
}
type getTaskTimeParams struct {
	Type     int   `form:"type"` //任务类型
	TimeFrom int64 `form:"time_from"`
	TimeTo   int64 `form:"time_to"`
}
type getTasksParams struct {
	Type int `form:"type"` //任务类型
	page.Params
}

type getTasksByRmsTaskId struct {
	TaskId uint64 `form:"task_id"`
	Type   int    `form:"type"` //任务类型
	page.Params
}

type getTasksByMainTaskCode struct {
	MainTaskCode string `form:"main_task_code"`
	Type         int    `form:"type"` //任务类型
	page.Params
}
type getTasksByKeys struct {
	MainTaskCode string `form:"main_task_code"`
	TaskId       uint64 `form:"task_id"`
	Type         int    `form:"type"` //任务类型
	page.Params
}

type getTaskStreamParams struct {
	MainTaskCode string `form:"main_task_code " binding:"required"` //主任务编号
}

type operateTaskParams struct {
	TaskID       uint64             `json:"task_id" binding:"required"`          //任务ID
	OperateCMD   model.TaskOperate  `json:"operate_cmd" binding:"oneof=0 1 2 3"` //操作指令:0=继续执行、1=任务暂停、2=任务取消、3 =强制完成
	CompleteType model.CompleteType `json:"complete_type" `                      //操作指令:0=正常完成 1=异常完成
}

type changeTaskGradeParams struct {
	TaskIds []uint64 `json:"task_ids" binding:"required"` //任务ID集合
	Grade   uint     `json:"grade" binding:"required"`    //优先级
}

type unlockMainTaskParams struct {
	MainTaskCode string `json:"main_task_code" binding:"required"` //主任务编号
}

type operateStationCMD uint8

const (
	SOCMDFree operateStationCMD = 0
	SOCMDLock operateStationCMD = 1
)

type stationOperateParams struct {
	MapName    string            `json:"map_name" binding:"required"`     //地图名称
	SiteId     string            `json:"site_id" binding:"required"`      //点位ID
	OperateCMD operateStationCMD `json:"operate_cmd" binding:"oneof=0 1"` //操作指令：0=释放、1=锁定
}

type areaOperateParams struct {
	MapName      string            `json:"map_name" binding:"required"`     //地图名称
	AreaId       string            `json:"area_id" binding:"required"`      //区域ID
	OperateCMD   operateStationCMD `json:"operate_cmd" binding:"oneof=0 1"` //操作指令：0=释放、1=锁定
	MainTaskCode string            `json:"main_task_code"`                  //主任务编号
}

type getMapsParams struct {
	MapName string `form:"map_name"`
}
type getOverviewMapParams struct {
	Name string `form:"name"`
}

type getBase64Map struct {
	MapName       string `json:"map_name"`        //地图名称
	Base64MapData string `json:"base64_map_data"` //地图Base64数据
}

type uploadBase64MapsParams struct {
	MapName   string      `json:"map_name" binding:"required"`   //地图名称
	ProjectId string      `json:"project_id" binding:"required"` //工程ID
	Name      string      `json:"name" binding:"required"`       //交通图名称
	MapData   base64.Data `json:"map_data" binding:"required"`   //base64地图(xml)
}

type uploadJsonMapsParams struct {
	MapName     string       `json:"map_name" binding:"required"`   //地图名称
	ProjectId   string       `json:"project_id" binding:"required"` //工程ID
	TrafficName string       `json:"name" binding:"required"`       //交通图名称
	MapXml      model.MapXml `json:"map_data" binding:"required"`   //json地图
}

type uploadOverviewJsonMapParams struct {
	model.MapOverview
}

type uploadFileMapsParams struct {
	ProjectId   string `json:"project_id" binding:"required"` //工程ID
	TrafficName string `json:"name" binding:"required"`       //交通图名称
}
type downloadFileMapsParams struct {
	MapName string `form:"map_name" binding:"required"` //地图名称
}

type operateMapCMD uint8

const (
	MOCMDDelete operateMapCMD = 1
)

type mapDeleteParams struct {
	MapName string `form:"map_name" binding:"required"`
}

type mapOverviewDeleteParams struct {
	Name string `form:"name" binding:"required"`
}

type mapSwitchRobotParams struct {
	AgvId   string `json:"agv_id" binding:"required"`   //机器人ID
	MapName string `json:"map_name" binding:"required"` //地图名称
}

type saveChargerParams struct {
	MapName    string   `json:"map_name" binding:"required"`
	SiteId     string   `json:"site_id" binding:"required"`
	ChargeID   uint8    `json:"charge_id" binding:"required"`
	ChargerIp  string   `json:"charge_ip" binding:"required"`
	ChargePort int      `json:"charge_port" binding:"required"`
	BanAgvList []string `json:"ban_agv_list" bson:"ban_agv_list"`
}

type deleteChargerParams struct {
	ChargeID uint8 `form:"charge_id" binding:"required"`
}

type deleteChargersParams struct {
	ChargeIds []uint8 `form:"charge_ids" binding:"required"`
}
type elevatorCodeParams struct {
	DeviceCode string `form:"device_code" binding:"required"`
}

type elevatorLevelParams struct {
	DeviceCode string `form:"device_code" binding:"required"`
	MapName    string `form:"map_name" binding:"required"`
}

type deleteMapRelationParams struct {
	FromMap string `json:"from_map" bson:"from_map" binding:"required"` //起始地图名
	StartId string `json:"start_id" bson:"start_id" binding:"required"` //起始点位id
	ToMap   string `json:"to_map" bson:"to_map" binding:"required"`     //终止地图名
	GoalId  string `json:"goal_id" bson:"goal_id" binding:"required"`   //终止点位id
}
type releaseFactoryParams struct {
	FromMap string `json:"from_map" binding:"required"` //起始地图名
	StartId string `json:"start_id" binding:"required`  //起始点位id
	ToMap   string `json:"to_map" binding:"required"`   //终止地图名
	GoalId  string `json:"goal_id" binding:"required"`  //终止点位id
}

type GetChargerParams struct {
	MapName string `form:"map_name" binding:"required"` //充电桩地图
	SiteId  string `form:"site_id" binding:"required"`  //充电桩点位
}

type releaseChargerParams struct {
	// MapName  string `json:"map_name" binding:"required"`  //充电桩地图
	// SiteId   string `json:"site_id" binding:"required"`   //充电桩点位
	ChargeId uint8 `json:"charge_id" binding:"required"` //充电桩ID
}
type releaseElevatorParams struct {
	DeviceCode string `json:"device_code" binding:"required"` //电梯信息编号
}
type enableElevatorParams struct {
	DeviceCode string `json:"device_code" binding:"required"` //设备编号
	Enable     bool   `json:"enable"`                         //是否启用
}
type enableDoorParams struct {
	DeviceCode string `json:"device_code" binding:"required"` //设备编号
	Enable     bool   `json:"enable"`                         //是否启用
	SiteId     string `json:"site_id" binding:"required"`     //点位
	MapName    string `json:"map_name" binding:"required"`    //地图名称
}

type getRMSLogsParams struct {
	TimeFrom int64 `form:"time_from"`
	TimeTo   int64 `form:"time_to"`
	Level    uint8 `form:"level"`
	page.Params
}

type getRobotsLogsParams struct {
	TimeFrom int64  `form:"time_from"`
	TimeTo   int64  `form:"time_to"`
	AgvID    string `form:"agv_id"`
	page.Params
}

type statisticType uint8

const (
	StatisticError    statisticType = 1 //1故障次数
	StatisticCharge   statisticType = 2 //2充电次数
	StatisticEffiency statisticType = 3 //3稼动率
)

type getStatisticParams struct {
	Type     statisticType `form:"type"`
	TimeFrom int64         `form:"time_from"`
	TimeTo   int64         `form:"time_to"`
	AgvID    string        `form:"agv_id"`
	page.Params
}
type getChargerStatisticParams struct {
	TimeFrom int64  `form:"time_from"`
	TimeTo   int64  `form:"time_to"`
	AgvID    string `form:"agv_id"`
	page.Params
}
type getSensorDataParams struct {
	AgvID      string `form:"agv_id"`
	SensorType int32  `form:"sensor_type"`
}

type setSensorDataParams struct {
	AgvID      string `json:"agv_id" binding:"required"`     //agv编号
	SensorType int32  `json:"sensor_type"`                   //设备类型 0:RFID 1:货物状态
	WriteData  string `json:"write_data" binding:"required"` //写入传感器（RFID）数据
}
type getResourcePictureParams struct {
	Tag string `form:"tag"`
}

type getSubtaskTemplateParams struct {
	TaskTemplateId int `form:"task_template_id"`
}

type SaveTaskTemplateParams struct {
	model.TaskTemplate
}

type SaveSubtaskTemplateParams struct {
	model.TaskItemTemplate
}
type SaveSubtaskTemplateListParams struct {
	TaskTemplateId      int                      `json:"task_template_id"`
	SubTaskTemplateList []model.TaskItemTemplate `json:"subtask_template_list"`
}

type DeleteTaskTemplateParams struct {
	Id int `form:"id"`
}

type DeleteSubtaskTemplateParams struct {
	TaskTemplateId int `form:"task_template_id"`
	Index          int `form:"index"`
}

type SaveSystemConfigParams struct {
	model.SystemConfig
}

type SaveSystemConfig_LogParams struct {
	model.LogCfg
}

type SaveSystemConfig_MiddlewareParams struct {
	model.MiddlewareCfg
}

type SaveSystemConfig_TimerChargerParams struct {
	model.DayChargerRule
}
type SaveSystemConfig_RuleId struct {
	Id uint16 `form:"id" ` //规则编号
}

type SaveSystemConfig_OnlineParams struct {
	model.RobotOnlineCfg
}

type SaveSystemConfig_TrafficParams struct {
	model.TrafficCfg
}

type saveStandbySiteParams struct {
	MapName    string   `json:"map_name" binding:"required"`     //地图名称
	SiteId     string   `json:"site_id" binding:"required"`      //点位
	BanAgvList []string `json:"ban_agv_list" binding:"required"` //禁用AGV集合
}

type saveStandbySiteGroupListParams struct {
	MapName        string   `json:"map_name" binding:"required"`          //地图名称
	SiteId         string   `json:"site_id" binding:"required"`           //点位
	AllowGroupList []string `json:"allow_group_list"  binding:"required"` //允许组号列表
}
type AccountVerifyParams struct {
	model.UserVerify
}

type SaveUserParams struct {
	model.User
}
type UserAccountParams struct {
	Account string `form:"account" binding:"required"` //地图名称
}
type SaveUserAuthorSwitch struct {
	Status usermanager.SwitchStatus
}

//获取待命点
type GetStandbySiteParams struct {
	MapName string `form:"map_name"` //地图名称
	SiteId  string `form:"site_id"`  //点位ID
}

//错误信息
type Err struct {
	Code     uint32 `json:"code"`      //错误码编号
	CodeHex  string `json:"code_hex"`  //错误码编号，十六进制
	Msg      string `json:"msg"`       //消息
	ToString string `json:"to_string"` //错误信息字符串
}

//地堆库相关
type uploadGroundLocationParams struct {
	model.GroundLocation
}

//地堆库相关
type updateOnGroundLocationParams struct {
	model.OneGroundLocation
}

//删除当前地图所有的库位
type deleteGroundLocationParams struct {
	MapName string `form:"map_name"` //地图名称
}

//删除单个库位
type deleteOneLocationParams struct {
	MapName string `form:"map_name"` //地图名称
	Group   string `form:"group"`    //组号
}

//获取单条地堆库
type getGroundLocationsByMapNameParams struct {
	MapName string `form:"map_name"` //地图名称
}
